package com.example.springbootabc.controller;

import com.example.springbootabc.entity.User;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value = {"/user"})
public class UserLoginController {


    @ResponseBody
    @RequestMapping(value = {"/login"})
    public String loginHtml(@RequestParam(value = "username", required = false) String username,
                            @RequestParam(value = "password", required = false) String password,
                            HttpServletRequest request) {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        ObjectMapper objectMapper=new ObjectMapper();
        String result="";
        try {
           result= objectMapper.writeValueAsString(user);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return "hello " + result;
    }
}
